package classes.buttons {
	import classes.sounds.SoundCollection;
	import flash.display.MovieClip;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Kihoonee
	 */
	public class BaseButton extends EventDispatcher {
		private var btn:MovieClip;
		private var _name:String;
		private var _visible:Boolean;
		
		public function BaseButton( _btn:MovieClip ) {
			btn = _btn;
			_name = _btn.name;
			
			btn.buttonMode = true;
			btn.addEventListener(MouseEvent.ROLL_OVER, btnEvent );
			btn.addEventListener(MouseEvent.ROLL_OUT, btnEvent );
			btn.addEventListener(MouseEvent.CLICK, btnEvent );
		}
		
		private function btnEvent(e:MouseEvent):void {
			if ( e.type === MouseEvent.ROLL_OVER ) {
				//trace(" 사운드 ");
				SoundCollection.rollOverSound();
				e.target.gotoAndStop(2);
			}else if ( e.type === MouseEvent.ROLL_OUT ) {
				e.target.gotoAndStop(1);
			}else if ( e.type === MouseEvent.CLICK ) {
				SoundCollection.clickSound();
				dispatchEvent( e.clone() );
			}
		}
		
		public function get name():String {
			return _name;
		}
		
		public function get visible():Boolean {
			return btn.visible;
		}
		
		public function set visible(value:Boolean):void {
			_visible = value;
			btn.visible = value;
		}
		
	}

}